//
//  SetPasswordView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2024/12/26.
//

import SwiftUI

struct AiActView: View {
    var forceShow = false
    @StateObject var viewModel = AiActViewModel()
    @EnvironmentObject var themeManager: ThemeManager
    @State private var isShow = false
    
    var body: some View {
        HStack{
            VStack(alignment: .leading, spacing: 18) {
                HStack{
                    Text("活动")
                        .foregroundColor(.bgItemContent)
                        .fontWeight(.bold)
                        .font(.system(size: 14))
                    Spacer()
                    Image(.myIconExpand)
                        .resizable()
                        .frame(width: 15,height: 15)
                        .rotationEffect(isShow ? Angle(degrees: 180) : .zero)
                }.contentShape(Rectangle())// 将整个矩形区域（包括padding）都设置为可点击区域
                 .onTapGesture {
                    withAnimation(Animation.easeInOut(duration: 0.3)) {
                        if !forceShow {
                            isShow.toggle()
                        }
                    }
                }
                
                if isShow{
                    HStack {
                        VStack(alignment:.leading){
                            Text("每月活动")
                                .foregroundColor(.bgItemContent)
                                .font(.system(size: 14))
                            Text("每月1次，Pro可领取\(configManager.getConfig().aiChat.aiMonthVipCount ?? 0)次回应，普通\(configManager.getConfig().aiChat.aiMonthCount ?? 0)次回应")
                                .foregroundColor(.bgNormalText4)
                                .font(.system(size: 10))
                        }
                        Spacer()
                        Image(.appIconArrowRight)
                            .resizable()
                            .frame(width: 15,height: 15)
                        
                    }.padding(.top,5).padding(.bottom,5)
                        .contentShape(Rectangle())
                        .onTapGesture {
                            viewModel.doMonthFree()
                        }
                    HStack {
                        VStack(alignment:.leading){
                            Text("每日活动")
                                .foregroundColor(.bgItemContent)
                                .font(.system(size: 14))
                            Text("每日1次，Pro可领取\(configManager.getConfig().aiChat.aiDayVipCount ?? 0)次回应，普通\(configManager.getConfig().aiChat.aiDayCount ?? 0)次回应")
                                .foregroundColor(.bgNormalText4)
                                .font(.system(size: 10))
                        }
                        Spacer()
                        Image(.appIconArrowRight)
                            .resizable()
                            .frame(width: 15,height: 15)
                        
                    }.padding(.top,5).padding(.bottom,5)
                        .contentShape(Rectangle())
                        .onTapGesture {
                            viewModel.doDayFree()
                        }
                    if configManager.getConfig().getSwitchConfig().isActInvite == true {
                        HStack {
                            VStack(alignment:.leading, spacing: 1){
                                HStack(spacing: 3) {
                                    Text("限时")
                                        .foregroundColor(.white)
                                        .font(.system(size: 8))
                                        .padding(.horizontal, 2)
                                        .padding(.vertical, 2)
                                        .background(.bgRed)
                                        .cornerRadius(3)
                                    Text("邀请活动")
                                        .foregroundColor(.bgItemContent)
                                        .font(.system(size: 14))
                                }
                                Text("邀请越多领取越多")
                                    .foregroundColor(.bgNormalText4)
                                    .font(.system(size: 10))
                            }
                            Spacer()
                            Image(.appIconArrowRight)
                                .resizable()
                                .frame(width: 15,height: 15)
                            
                        }.padding(.top,5).padding(.bottom,5)
                            .contentShape(Rectangle())
                            .onTapGesture {
                                pathManager.jump(type: JumpType.INVITE_ACT)
                            }
                    }
                }
            }
            Spacer()
        }.frame(maxWidth: .infinity).padding(18).background(.bgItem).clipShape(RoundedRectangle(cornerRadius: 15))
            .onAppear {
                if forceShow {
                    isShow = true
                }
            }
    }
}

//#Preview {
//    SetPasswordView()
//}

//定义预览提供者
struct AiAct_Previews: PreviewProvider {
    static var previews: some View {
        //使用预览共享配置
        configurePreviewEnvironment(for: AiActView(forceShow: true))
    }
}
